package com.hzdl.order.config;

import com.hzdl.order.entity.Order;
import com.hzdl.order.repository.OrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Configuration
public class DataInitializer {
    
    @Bean
    CommandLineRunner initDatabase(OrderRepository repository) {
        return args -> {
            Order order1 = new Order();
            order1.setGoodsId(1);
            order1.setOrderNumber("ORD001");
            order1.setAmount(new BigDecimal("99.99"));
            order1.setCreateTime(LocalDateTime.now());
            order1.setTime("2020-11-11 00:01");
            repository.save(order1);
            
            Order order2 = new Order();
            order2.setGoodsId(2);
            order2.setOrderNumber("ORD002");
            order2.setAmount(new BigDecimal("199.99"));
            order2.setCreateTime(LocalDateTime.now());
            order2.setTime("2020-11-11 00:02");
            repository.save(order2);
        };
    }
} 